<template>
	<view class="uni-flex uni-column">
		<view class="flex-item flex-item-V">
			<swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
				<swiper-item v-for="(item, index) in homedata.adlist" :key="index">
					<image class="image"  :src="item.img" 
					:style="{width: '100%', height: homedata.topimgsize + 'px'}"
					 />
				</swiper-item>
			</swiper>
		</view>

		<view class="flex-item flex-item-V">
			<view class="uni-flex uni-row">
				<view class="flex-item uni-center"
				v-for="(item, index) in homedata.typelist" :key="index"
				style="width:20%; padding-top:20px;"
				>
					<image :src="item.logo" 
					:style="{ width: homedata.typeimgsize + 'px', height: homedata.typeimgsize + 'px' }"
					 />
					 <br>
					<text>{{item.type_name}}</text>
				</view>
			</view>
		</view>
        <view class="flex-item flex-item-V"
        v-for="(item, index) in homedata.columnlist" :key="index"
        >
        	<page-head :title="item.column_name"></page-head>
        	<view class="uni-product-list">
				<view class="uni-product" 
				v-for="(product,index1) in item.columnproductlist" :key="index1">
					<view class="image-view">
						<image class="uni-product-image" :src="product.img"></image>
					</view>
					<view class="uni-product-title">{{product.name}}</view>
					<view class="uni-product-price">
						<text class="uni-product-price-original">￥{{product.guide_price}}</text>
					</view>
				</view>
			</view>
        </view>
        <view class="flex-item flex-item-V">

        	<view class="uni-product-list">
				<view class="uni-product" 
				v-for="(product,index) in homedata.muilist" :key="index">
					<view class="image-view">
						<image class="uni-product-image" :src="product.img"></image>
					</view>
					<view class="uni-product-title">{{product.name}}</view>
					<view class="uni-product-price">
						<text class="uni-product-price-original">￥{{product.guide_price}}</text>
					</view>
				</view>
			</view>

        </view>
		
		
	</view>
</template>
<script>

import http from '../../../common/http';
import util from '../../../common/util';
import { mapGetters, mapActions } from 'vuex'

export default {
	data() {
		return {
			adlist : [
				{url : '123456'},
				{url : '123456'},
				{url : '123456'},
			],
				
			indicatorDots: true,
			autoplay: true,
			interval: 2000,
			duration: 500,


			homedata : {},
		}
	},
	computed : {
		...mapGetters([
			'URL',
      	]),
	},
	async onLoad() {
		// const openid = await this.getUserOpenId();
		// console.log(openid);

		const userInfo = await this.getUserInfo();
		console.log('userinfo');
		console.log(userInfo);

		http({
			fun : 'homePageData',
			cb : res => {
				console.log(res);
				this.homedata = res;
				//处理轮播图
				for(let i = 0; i < this.homedata.adlist.length; i++){
					let tmp = this.homedata.adlist[i];
					tmp['img'] = util.changeImg(tmp.url, 'normal');
				}

				//处理类别图片
				for(let i = 0; i < this.homedata.typelist.length; i++){
					let tmp = this.homedata.typelist[i];
					tmp['img'] = util.changeImg(tmp.logo, 'typeimg');
				}

				//处理栏目的图片
				for(let i = 0; i < this.homedata.columnlist.length; i++){
					let tmp = this.homedata.columnlist[i];
					for(let j = 0; j < tmp.columnproductlist.length; j++){
						let tmp1 = tmp.columnproductlist[j];

						let result = this.URL.defaultImg;
						if(tmp1.top_pic != undefined){
							var ttt = JSON.parse(tmp1.top_pic);
                  			result = util.cutImage(ttt[0]);
						}

						tmp1['img'] = result;
					}
				}

				//处理产品图片
				for(let i = 0; i < this.homedata.muilist.length; i++){
					let tmp = this.homedata.muilist[i];

					let result = this.URL.defaultImg;
					if(tmp.top_pic != undefined){
						try{
							var ttt = JSON.parse(tmp.top_pic);
              				result = util.cutImage(ttt[0]);
						}catch(err){

						}
					}

					tmp['img'] = result;
				}
			},
			err : res => {
				console.log(res);
			},
			final : () => {
				console.log('final');
			}
		});
	},
	onShareAppMessage() {
		
	},
	onNavigationBarButtonTap(e) {
		uni.navigateTo({
			url: '/pages/about/about'
		});
	},
	onShareAppMessage() {
		console.log('啦啦啦啦啦');
	},
	methods: {
		...mapActions(['getUserOpenId', 'getUserInfo']),
	},

}
</script>

<style>
	
</style>
